package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController //注解controller层，只返回结果不反回视图。
@Slf4j //用作日志输出的，添加了该注释之后，就可以在代码中直接饮用log.info( ) 打印日志了
public class PaymentController {

    @Resource //@Resource主要做依赖注入的，从容器中自动获取bean，和@Autowired用法相似
    private PaymentService paymentService;

    @Value("${server.port}")//暴露服务端口，这个是yml文件的服务端口。
    private String serverport;

    @GetMapping("/payment/hystrix/ok/{id}")//url访问的路径
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        String result = paymentService.paymentInfo_OK(id);
        log.info("********result: "+result);
        log.info("---------:微服务的端口${server.port}"+serverport);
        return result;
    }
    @GetMapping("/payment/hystrix/timeout/{id}")//url访问的路径
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
        String result = paymentService.paymentInfo_TimeOut(id);
        log.info("********result: "+result);
        log.info("---------:微服务的端口${server.port}"+serverport);
        return result;
    }
    /**
     * 服务熔断
     * */
    @GetMapping("/payment/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id){
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("****result: "+result);
        return result;
    }
}
